﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace HZ.Supervise.Web.Common
{
    public partial class FindPrescription : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            dataBind();
            if (IsPostBack)
            {
                bindList();
            }
        }
        /// <summary>
        /// 数据绑定
        /// </summary>
        private void dataBind()
        {
            int i;
            string strHostpitalid = "";
            strHostpitalid = Request.QueryString["id"].ToString();
            string  strwhere = "and a.PSbsidyAmount<a.PSubsidiesAmount and POrderStatus =1  ";
            strwhere += "and PHospitalName='"+strHostpitalid+"'";
            if (!txtproductName.Text.Trim().Equals(""))
            {
                strwhere += "PrescriptionName like'%"+txtproductName.Text.Trim()+"%'"; 
            }
            if (!txtStratTime.Text.Trim().Equals("")) //开始时间
            { strwhere += " and a.PSubmitTime >='" + (new HZ.Common.ConvertHelper(txtStratTime.Text.Trim()).ToDateTime).Value.ToString() + "'"; }
            if (!txtEndTime.Text.Trim().Equals("")) //结束时间
            { strwhere += " and a.PSubmitTime <='" + (new HZ.Common.ConvertHelper(txtEndTime.Text.Trim()).ToDateTime).Value.ToString() + "'"; }
            HZ.Supervise.IBLL.IBLL_Prescription iPrescription = HZ.Supervise.BLLFactory.IBl_Prescription();
            DataTable dt = iPrescription.GetHospitalePrescrioDetail2(strwhere, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out i);
            
            gvwAreaList.DataSource = dt;
            AspNetPager1.RecordCount = i;
            gvwAreaList.DataBind();
        }
        /// <summary>
        /// 绑定List控件集合
        /// </summary>
        private void bindList()
        {
            string[] hosName = this.PrescriptionName.Value.Split(',');
            string[] hosId = this.PrescriptionId.Value.Split(',');
            this.ListPrescription.Items.Clear();
            for (int i = 0; i < hosName.Length; i++)
            {
                if (hosName[i].Equals(""))
                {
                    return;
                }
                ListItem item = new ListItem();
                item.Text = hosName[i];
                item.Value = hosId[i];
                this.ListPrescription.Items.Add(item);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            dataBind();
        }

        protected void HzButton1_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            dataBind();
        }
    }
}
